<?php
/*  个人专栏
*/
class ColumnAction extends Action {
  private $_dev = 0;
  private $_uid = 0;
  private $_isAdmin=false;
  private $_username = NULL;
  //用来构造个人专栏的表头导航，把相关的参数传到group-member-base.html中即可，column_type代表类型，sub_id代表具体的文章/相册的id
  private $_columns = array(
    1=>array(column_type=>1),//社区首页=>***专栏首页
    2=>array(column_type=>2,sub_id=>0),//社区首页=>***个人专栏=>***(具体文章标题)
    3=>array(column_type=>3),//社区首页=>***个人专栏=>相册
    4=>array(column_type=>4,sub_id=>0),//社区首页=>***个人专栏=>相册=>****（相册名称）
  );
  function _initialize() {
    $this->_dev = C("DEV_FLAG");
    $this->assign("dev", $this->_dev);
	
   if(empty($_REQUEST['isAjax'])){//ajax请求，不检查uid
	//dump($this->_isAdmin);
     $m = M("PwMembers");
	 if(!empty($_REQUEST["uid"]))
	   $map['pw_members.uid']=array("eq",$_REQUEST["uid"]);
	 elseif(!empty($_REQUEST["username"]))
	   $map['username']=array("eq",$_REQUEST["username"]);
	 else{
      $jumpUrl = "__APP__/Circle/";
      $this->assign("jumpUrl", $jumpUrl);
      $this->error("你所访问的用户不存在");
     }
	   
    $result = $m->where($map)->join("pw_memberdata on pw_memberdata.uid=pw_members.uid")->find();
	//exit($m->getLastSQL());
    
    if ($result) {
      $this->_uid = $result["uid"];
      $this->_username = $result["username"];
      $this->assign("username", $this->_username);
    }
    else {
       $jumpUrl = "__APP__/Circle/";
       $this->assign("jumpUrl", $jumpUrl);
       $this->error("你所访问的用户不存在");
      }
	  $this->assign("istp", 1);//circle-header2中有TP和PHPWIND都用到，加上这个参数进行区别
      $this->assign("isColumn",1);
	}//end if 
	$this->_isAdmin=isset($_COOKIE["tpxslmluserid"])&&$_COOKIE["tpxslmluserid"]==$this->_uid;//判断是否为专栏作者
	$this->assign('isAdmin',$this->_isAdmin);//是否未专栏作者
	
  }

  //格式化图片，1-用户，2-群组
  private function _formatIcon($icon,$type) {
    if ($type == 1) {
	$img= "/pw8/images/face/none.gif";
      $icons = explode('|',$icon);
      //$icon = $icons[1]>0 ? "/pw8/attachment/upload/middle/".$icons[0] : "/pw8/images/face/none.gif";
	  if(empty($icons[1]))
		   $img= "/pw8/images/face/none.gif";
	   else{
	     switch($icons[1]){
		   case 1:{ $img= "/pw8/images/face/".$icons[0];};break;//系统头像
		   case 2:$img=$icons[0];break;//网络头像
		   case 3:{		      
		     if(count($icons)>4){
			   $icons[0]=str_replace('.gif','.jpg',$icons[0]);
			   $icons[0]=str_replace('.png','.jpg',$icons[0]);
			   $img="/pw8/attachment/upload/middle/".$icons[0];
			  }
			 else 
			   $img="/pw8/attachment/upload/".$icons[0]; 		     
		   };break;//上传头像
		 }	   
	   }
    }else {
	    ///pw8/attachment/cn_img/
	   //pw8\attachment\photo\
	   $img= "/pw8/images/g/groupnopic.gif";
	   if(!empty($icon) && strpos($icon,'/'))
	      $img="pw8/attachment/photo/".$icon;
	   elseif(!empty($icon))
	     $img="pw8/attachment/cn_img/".$icon;
    }
    return $img;
  }

  //截取utf8字符串
  private function _utf8Substr($str, $from, $len) {
    return preg_replace('#^(?:[\x00-\x7F]|[\xC0-\xFF][\x80-\xBF]+){0,'.$from.'}'.
      '((?:[\x00-\x7F]|[\xC0-\xFF][\x80-\xBF]+){0,'.$len.'}).*#s',
      '$1',$str);
  }

  //格式化内容摘要，包括去掉html和截取字段等
  private function _formatKeyContent($content) {
    $rt = str_replace('[', "<", $content);
    $rt = str_replace(']', ">", $rt);
    $rt = preg_replace("/(<img>)(\S)+<\/img>/", "", $rt);
    $rt = strip_tags($rt);
    $rt = $this->_utf8Substr($rt, 0, 100);
    return $rt;
  }

  public function index() {
    $base = $this->_getMemberBase($this->_uid);//当前用户资料
    $newest = $this->_getNewest($this->_uid);//首页显示内容
    $this->assign("uid", $this->_uid);
    $this->assign("base",$base);
    $this->assign("newest", $newest);
    $this->assign('column_type', 1);
    $m=M('PwSpace');
    $m->setInc('visits',"uid=".$this->_uid);
    $this->assign("username", $this->_username);
    //echo $m->getLastSQL();
	//dump($newest);
    $this->display();
  }
  
  /*diary 展示*/
  public function diaryView(){
     $did=empty($_GET['did'])?0:$_GET['did'];
	 $base = $this->_getMemberBase($this->_uid);//当前用户资料
	 $m=D('PwDiary');
	 $item=$m->find($did);
	 if(!$item){
	   $this->error('该博文不存在');
	   exit();
	 }
	
	 //$m=M('PwComment');
	 //$cCum=$m->where("type=diary and typeid={$did}")->count();
	 //$m->setInc('r_num',"did={$did}");
	 
	 //0：全站可见 1：仅好友可见 2:仅自己可见
	 //文章隐私检查
	 $isAllow=$m->allowReading($did,$this->_uid);
	 if($isAllow!=''){
	   $this->error($isAllow);
	   exit();
	 }
	 $newest = $this->_getNewest($this->_uid);//首页显示内容
	 //exit('bbb');
     $this->assign("uid", $this->_uid);
     $this->assign("newest", $newest);
	 $this->assign('item',$item);
	 $this->assign('nav',$nav);
	 $this->assign('base',$base);
     $this->assign('column_type', 2);
     $this->assign('sub_id', $did);
	 $this->display('column_article');
  
  }
  

  
  //列出评论列表,1=文章，2=图片
  public function getCommentAjax(){
     $types=array('1'=>'diary','2'=>'photo');
     $did=empty($_REQUEST['id'])?0:$_REQUEST['id'];
	 $type=empty($_REQUEST['type'])?1:$_REQUEST['type'];
      
     $m=M('PwComment');
	 $count=$m->where("`type`='{$types[$type]}' and upid=0 and  typeid={$did}")->count();
	 $_GET=$_POST;
	 import("@.ORG.page");//
	 $p=new page($count,5);
	 $list=$m->where("`type`='{$types[$type]}' and typeid={$did}")->order('postdate desc')->limit("$p->firstRow,$p->listRows")->select();
	 $this->assign('list',$list);
	 //$this->assign('isAdmin',$this->_isAdmin);
	 $this->display('comment');
    // alert($_REQUEST);
	 //alert($m->getLastSQL());
  }
  
  public function delColonyAjax(){
    if(empty($_GET['id'])){
	  echo json_encode(array('r'=>'0'));
	} else{
	  $m=M('PwComment');
	  $item=$m->find($_GET['id']);
	  if($m->delete($_GET['id'])){
	    //echo json_encode(array('r'=>'1'));
		if($item['type']=='diary') {//修改评论数
		  $m=M('PwDiary');
		  $m->setDec('c_num','did='.$item['typeid']);
		  }elseif($item['type']=='photo'){
		     $m=M('PwCnphoto');
		    $m->setDec('c_num','pid='.$item['typeid']);
		  }
		 $one=$m->find($item['typeid']);
		 echo json_encode(array('r'=>$one['c_num'])); 
	   }//end 操作成功
	  else//操作失败
	    echo json_encode(array('r'=>'0'));	   
	} 
  }
  
  
  public function commentSave(){
       if(empty($_POST['did']) && empty($_POST['pid'])){
	     echo json_encode(array('r'=>0));
		 exit();
	   }
	   $circle=A('Circle');//检查登录状态
	   $user=$circle->userInfo();	   
	   
	   
	   $id=empty($_POST['did'])?$_POST['pid']:$_POST['did'];
	   
       $data['type']=$_POST['type'];
	   $data['typeid']=$id;
	   $data['title']=$_POST['content'];
	   $data['uid']=$user['id'];
	   $data['username']=$user['name'];
	   $data['postdate']=time();
	   $m=M('PwComment');
	   
	   if($m->add($data)){
	     if($_POST['type']=='diary'){
		   $m=M('PwDiary');
		   $m->setInc('c_num','did='.$id);
		   }
		 else{
		    $m=M('PwCnphoto');
			$m->setInc('c_num','pid='.$id);
		  }
		 //exit($m->getLastSQL());
		 $one=$m->find($id);
		 echo json_encode(array('r'=>$one['c_num']));
		}else{
		    echo json_encode(array('r'=>0));
		}
	   
  }
  
  /*用户相册*/
  public function album(){
	 $base = $this->_getMemberBase($this->_uid);//当前用户资料
	 $newest = $this->_getNewest($this->_uid);//首页显示内容
	 
	 $m=M('PwCnalbum');
	 $count=$m->where("private=0 and atype=0 and  ownerid=".$this->_uid)->count();
	 import('@.ORG.Page');
	 $page=new Page($count,10);
	 $nav=$page->show();
	 $list=$m->where("private=0 and photonum>0 and atype=0 and  ownerid=".$this->_uid)->order('crtime DESC')->limit("$page->firstRow,$page->listRows")->select();	 
	 
	 $m=M('PwCnphoto');
	 $photo=$m->where("private=0 and photonum>0 and atype=0 and ownerid=".$this->_uid)->join("pw_cnalbum on pw_cnalbum.aid=pw_cnphoto.aid")->order('uptime DESC')->limit(10)->select();
	 //echo $m->getLastSQL();
     $this->assign("uid", $this->_uid);
     $this->assign("newest", $newest);
	 $this->assign('list',$list);
	 $this->assign('photo',$photo);
	 $this->assign('base',$base);
	 $this->assign('nav',$nav);
     $this->assign("column_type", 3);
	 $this->display();  
  
  }
  
    /*用户相册图片列表*/
  public function albumList(){
	 $base = $this->_getMemberBase($this->_uid);//当前用户资料
	 $newest = $this->_getNewest($this->_uid);//首页显示内容
	 $aid=empty($_GET['aid'])?0:$_GET['aid'];
	 
	 
	 $m=M('PwCnphoto');
	 import('@.ORG.Page');
	 
	 $count=$m->where("aid={$aid}")->count();
	 $page=new Page($count,5);
	 $nav=$page->show();
	 $list=$m->field('pw_cnphoto.*, pw_cnalbum.aname')
	         ->where("pw_cnalbum.aid={$aid} and atype=0 and ownerid={$this->_uid}")
			 ->join("pw_cnalbum on pw_cnalbum.aid=pw_cnphoto.aid")
			 ->limit("$page->firstRow,$page->listRows")
			 ->order('uptime DESC')
			 ->select();	 
	
	 if(!$list){
	   $this->error('该相册不存在或该相册暂无图片');
	   exit();
	 }
	// echo 'aa'.$apge->totalPages;
	 //dump($page);
     $this->assign("uid", $this->_uid);
     $this->assign("newest", $newest);
	 $this->assign('list',$list);
	 $this->assign('nav',$nav);
	// $this->assign('photo',$photo);
	 $this->assign('base',$base);
	 //$this->assign('nav',$nav);
     $this->assign('column_type', 4);
     $this->assign('sub_id', $aid);
	 $this->display('albumList2');  
  }
  
      /*用户相册图片列表AJAX*/
  public function albumListAjax(){
	 $aid=empty($_GET['aid'])?0:$_GET['aid'];
	 
	 
	 $m=M('PwCnphoto');
	 import('@.ORG.Page');
	 
	 $count=$m->where("aid={$aid}")->count();
	 $page=new Page($count,5);
	 $nav=$page->show();
	 $list=$m->field('path')
	         ->where("aid={$aid}")
			 ->limit("$page->firstRow,$page->listRows")
			 ->order('uptime DESC')
			 ->select();	 
			// dump($list);
	 if($list){
	   echo json_encode(array('r'=>'1','list'=>$list));
	 }
	 else{echo json_encode(array('r'=>'0'));}
  }
  
  
  //作者所在群组
  public function userGroup(){
     $base = $this->_getMemberBase($this->_uid);//当前用户资料
	 $newest = $this->_getNewest($this->_uid);//首页显示内容
	 
	 $m=M('PwCmembers');
	 import('@.ORG.Page');
	 
	 $count=$m->where("uid={$this->_uid}")->count();
	 $page=new Page($count,20);
	 $nav=$page->show();
	 $list=$m->field('t1.*')
	         ->where("pw_cmembers.uid={$this->_uid}")
			 ->join("pw_colonys t1 on  t1.id=pw_cmembers.colonyid")
			 ->limit("$page->firstRow,$page->listRows")
			 ->order('createtime DESC')
			 ->select();	 
    $m=D('PwColonys');
	//$m->getIconByList($list);
	foreach($list as &$li){
	   //$li['cnimg']=$this->_formatIcon($li['cnimg'],2);
	   $li["cnimg"]=!empty($li["cnimg"])?"http://www.ehs.cn/pw8/attachment/cn_img/".$li["cnimg"]:"http://www.ehs.cn/pw8/images/g/groupnopic.gif";
	}
	// echo 'aa'.$apge->totalPages;
     $this->assign("uid", $this->_uid);
     $this->assign("newest", $newest);
	 $this->assign('list',$list);
	 $this->assign('nav',$nav);
	 $this->assign('gNum',$count);
	// $this->assign('photo',$photo);
	 $this->assign('base',$base);
	 //$this->assign('nav',$nav);
	 $this->display('user_group');   
  }
  
  /*用户相册图片展示*/
  public function albumDetail(){
  
     // Array indexes are 0-based, jCarousel positions are 1-based.
	 $aid=empty($_GET['aid'])?0:$_GET['aid'];
     $first = max(0, intval($_GET['first']) - 1);
     $last  = max($first + 1, intval($_GET['last']) - 1);

     $length = $last - $first + 1;

     $m=M('PwCnphoto');
	 
	 //$count=$m->where("aid={$aid}")->count();
	 //$page=new Page($count,5);
	 //$nav=$page->show();
	 $list=$m->where("aid={$aid}")
			 //>join("pw_cnalbum t1 on  t1.aid=pw_cnphoto.aid")
			 //->limit("$page->firstRow,$page->listRows")
			 ->order('uptime DESC')
			 ->select();		
     $images=array();
	 foreach($list as $li){
	   $images[]='/pw8/attachment/'.$li['path'].'|'.$li['pid'].'|'.$li['pintro'].'@'.$li['c_num'];
	 }
	// dump($images);
    /*$images = array(
       'http://static.flickr.com/66/199481236_dc98b5abb3_s.jpg',
       'http://static.flickr.com/75/199481072_b4a0d09597_s.jpg',
       'http://static.flickr.com/57/199481087_33ae73a8de_s.jpg',
       'http://static.flickr.com/77/199481108_4359e6b971_s.jpg',
       'http://static.flickr.com/58/199481143_3c148d9dd3_s.jpg',
       'http://static.flickr.com/72/199481203_ad4cdcf109_s.jpg',
       'http://static.flickr.com/58/199481218_264ce20da0_s.jpg',
       'http://static.flickr.com/69/199481255_fdfe885f87_s.jpg',
       'http://static.flickr.com/60/199480111_87d4cb3e38_s.jpg',
       'http://static.flickr.com/70/229228324_08223b70fa_s.jpg',
    );*/

$total    = count($images);
$selected = array_slice($images, $first, $length);

// ---

header('Content-Type: text/xml');

echo '<data>';

// Return total number of images so the callback
// can set the size of the carousel.
echo '  <total>' . $total . '</total>';

foreach ($selected as $img) {
    echo '  <image>' . $img . '</image>';
}

echo '</data>';
  }

  private function _getMemberBase($uid) {
    $m = M("PwMembers");
    $result = $m->where("pw_members.uid ={$uid} ")
      ->join("pw_space on pw_space.uid=pw_members.uid")//空间信息
      ->join("pw_membercredit on pw_membercredit.uid=pw_members.uid")//积分信息
      ->find();

    $result["icon"] = $this->_formatIcon($result["icon"],1); //用户头像
    if(empty($result['value']))$result['value']=0;

    switch($result["gender"]) {                               //用户性别
      case 0:$result['gender']='--';
        break;
      case 1:$result['gender']='男';
        break;
      case 2:$result['gender']='女';
        break;
    }


    $m=M('pw_usergroups');
    if(!empty($result['memberid'])) {                          //等级信息
      $item=$m->where("gid={$result['memberid']}")->find();
      //dump($item);
      $result['level']=$item['grouptitle'];
    }
    if(!empty($result['groupid'])) {                            //身份信息，如VIP
      $item=$m->where("pw_usergroups.gid={$result['groupid']}")->find();
      $result['sf']=$item['grouptitle'];
    }
    //dump($result);
    return $result;
  }



  //获取最新动态，包括：博文(1)，群组文章(1)，微博(2)，个人相册，留言板
  private function _getNewest($uid) {
    $rt = array();
    $m = M('PwDiary');
    //博文-1
	import("@.ORG.Page"); //导入分页类
	$map['uid']=array('eq',$uid);
	//$map['privacy']=array('eq',0);
	if(isset($_GET['type']) && $_GET['type']!='')
	$map['dtid']=$_GET['type'];
	
			
   // $sql = "select * from pw_diary where uid =  and privacy = 0";
    $diary = $m->where($map)->select();
	$page=new Page(count($diary),6);
	$nav=$page->show();
	
	$diary=$m->where($map)->limit("$page->firstRow,$page->listRows")->order("postdate DESC")->select();
	
    $rt['diary']['nav']=$nav;//分页内容
	foreach($diary as &$d){
       // $d["content"]= $this->_formatKeyContent($d["content"]);
	   //$d["content"]=mb_substr($d["content"], 0, 300);
	   //msubstr($str, $start=0, $length, $charset="utf-8″, $suffix=true)
	   $d["content"]=strip_tags($d["content"]);
	   $d["content"]=msubstr($d["content"], $start=0,280, $charset="utf-8");
	 }
	$rt['diary']['list']=$diary;
	
	//文章数和评论数
	$aNum=$m->where("uid=".$uid)->count();	
	$dNum=$m->where("dtid=0 and uid=".$uid)->count();
	$m=M("PwComment");
	$cNum=$m->where(" type='diary' and typeid in(select id from a_pw_colonys_article where uid={$uid})")->count();
	//echo $m->getLastSQL();
	$rt['aNum']=empty($aNum)?0:$aNum;//文章总数
	$rt['cNum']=empty($cNum)?0:$cNum;//总文章评论数
	$rt['dNum']=empty($dNum)?0:$dNum;//默认文章分类数
	
	
    //群组文章-1
    $sql = "select t1.id,t1.cyid,t1.title from a_pw_colonys_article t1  where uid = $uid order by create_time desc limit 5";
    $article = $m->query($sql);
    
	/*foreach($article as &$a){
      $a["content"]= $this->_formatKeyContent($a["content"]);
	 }*/
	 $rt['article']=$article;
	 //
    /*//微博-2 ,type=0,日志；
    $sql = "select * from pw_weibo_content where uid = $uid and type=0 order by postdate DESC limit 0,3";
    $weibo = $m->query($sql);
    $rt["weibo"] = count($weibo)>0 ? $weibo : "";*/
	//最新评论
	$m=M("APwColonysArticle");
	$list=$m->distinct(a_pw_colonys_article.id)
	        ->field("a_pw_colonys_article.id,
	                a_pw_colonys_article.cyid,
	                a_pw_colonys_article.title")
			->where('a_pw_colonys_article.uid='.$uid)
			->join('a_pw_colonys_article_comment t2 on a_pw_colonys_article.id=t2.aid')
			->order("t2.create_time DESC")
			->limit(5)
			->select();
		//	exit($m->getLastSQL());
	$rt['commend']=$list;
	
	
	
	//文章分类
	$m=M('PwDiarytype');
	$list=$m->where('uid='.$uid)->select();
	$rt['aType']=$list;
	

	
	//推荐文章
	$circle=A('Circle');
	$list=$circle->_getDiaryList(3);
	$rt['tjArr']=$list;
	
	//dump($rt['commend']);exit();
    return $rt;
  }

  //个人博文列表
  public function diarys() {
    $m = M("PwDiary");
    import("@.ORG.Page"); //导入分页类
    $records = 10;//每页多少条记录
    $where = "privacy = 0 and uid = ".$this->_uid;
    $count = $m->where($where)->count();
    $p = new Page ($count,$records);
    $p->setConfig('header','篇记录');
    $p->setConfig('prev',"上一页");
    $p->setConfig('next','下一页');
    $p->setConfig('first','<<');
    $p->setConfig('last','>>');
    $page = $p->show ();
    //$list = $m->field("t1.*")->Table("t1")->join("pw_diarytype t2 on (t2.dtid = t1.dtid)")->where($where)->order("postdate desc")->limit($p->firstRow.",".$p->listRows)->select();
    $sql = "select t1.*,t2.name as type_name
      from pw_diary t1 left join pw_diarytype t2 on (t1.dtid = t2.dtid)
      where t1.privacy = 0 and t1.uid = ".$this->_uid." order by postdate desc limit ".$p->firstRow.",".$p->listRows;
    $list = $m->query($sql);
    foreach($list as $k => $v) {
      $list[$k]["content"] = $this->_formatKeyContent($v["content"]);
    }

    //$this->_user["icon"] = $this->_formatIcon($this->_user["icon"],1);
    $this->assign('base',$this->_getMemberBase($this->_uid));
    //$this->assign("count", $count);
    $this->assign("list", $list);
    ///*$this->assign("nowPage",$p->nowPage);
    $this->assign("page", $page );
    //$this->assign("records",$records);*/
    $this->assign("uid",$this->_uid);
    $this->assign("tab",2);
    $this->display('article');
  }


  //个人组群 文章
  public function articleList() {
    $m = M("APwColonysArticle");
    import("@.ORG.Page"); //导入分页类
    $records = 10;//每页多少条记录
    $where = "uid = ".$this->_uid;
    $count = $m->where($where)->count();
    $p = new Page ($count,$records);
    $p->setConfig('header','篇记录');
    $p->setConfig('prev',"上一页");
    $p->setConfig('next','下一页');
    $p->setConfig('first','<<');
    $p->setConfig('last','>>');
    $page = $p->show ();
    //$list = $m->field("t1.*")->Table("t1")->join("pw_diarytype t2 on (t2.dtid = t1.dtid)")->where($where)->order("postdate desc")->limit($p->firstRow.",".$p->listRows)->select();

    $list =$m->field("a_pw_colonys_article.*,pw_colonys.cname")->where($where)->order('create_time DESC')->join('pw_colonys on a_pw_colonys_article.cyid=pw_colonys.id')->limit("$p->firstRow,$p->listRows")->select();
    foreach($list as $k => $v) {
      $list[$k]["content"] = $this->_formatKeyContent($v["content"]);
    }
    $this->_user["icon"] = $this->_formatIcon($this->_user["icon"],1);
    $this->assign('base',$this->_getMemberBase($this->_uid));
    //$this->assign("count", $count);
    $this->assign("list", $list);
    ///*$this->assign("nowPage",$p->nowPage);
    $this->assign("page", $page );
    //dump($page);
    //$this->assign("records",$records);*/
    $this->assign("uid",$this->_uid);
    $this->assign("tab",3);
    $this->display('article');
  }

  //个人微博列表
/*  public function weibo() {
    $m=M('PwWeiboContent');
    $count=$m->where("uid=$this->_uid")->count();
    import("@.ORG.Page"); //导入分页类
    $records = 10;//每页多少条记录
    $p = new Page ($count,$records);
    $list=$m->where("uid=$this->_uid")->limit("$p->firstRow,$p->listRows")->order("postdate DESC")->select();
    $nav=$p->show();

    foreach($list as &$li) {
      $comment=$this->_weiboComment($li['mid'],1);
      if($comment)
        $li['comment']=$comment[0];
      else
        $li['comment']=NULL;
    }
    //dump($list);
    //dump($list);
    $this->assign('base',$this->_getMemberBase($this->_uid));
    $this->assign("list", $list);
    $this->assign("page", $page );
    $this->assign("uid",$this->_uid);
    $this->display('blogging');
  }*/


  /*用户推荐文章操作*/
  public function setPromoteAjax() {
    $type=empty($_GET['type'])?'':$_GET['type'];
    $obj_id=empty($_GET['id'])?'':$_GET['id'];
    if($type=='' || $obj_id=='') {
      echo json_encode(array('result'=>'0'));
    }

    $tables=array('a'=>'APwColonysArticle','d'=>'PwDiary');//a_pw_colonys_article
    //$fields=array('a'=>'recommend_num','d'=>'c_num');
	$keys=array('a'=>'id','d'=>'did');

    $m=M($tables[$type]);
    $m->setInc('recommend_num',"$keys[$type]={$obj_id}");
	//alert($m->getLastSQL());
    $item=$m->field("recommend_num as result")->find($obj_id);
	
    echo json_encode($item);
  }


  //微博评论
  /*
  *$mid=微博id，num=返回数量
  */
  private function _weiboComment($mid,$num=1) {
    $m=M('PwWeiboComment');
    $list=$m->where("mid={$mid}")->join('pw_members on pw_members.uid=pw_weibo_comment.uid')->limit($num)->select();
    //echo $m->getLastSQL();
    return $list;
  }

  /*//博文内容页
  public function diary(){
    $id = $_GET["id"];
    $m = M("PwDiary");
    $article = $m->where("did = $id")->find();
    dump($article);
  }*/
}
?>